package com.doform.android.xianggucheng.popwindow;

import android.app.AlertDialog;
import android.content.Context;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;

/**
 * 作者 Y_MS
 * Created by ${APEN} on 2017/6/3.
 * GitHub：https://github.com/cxydxpx
 */

public class CommonDialog extends AlertDialog {

    private Context mContext;
    private ListView mListView;
    private int mLayoutId;
    private View mConvertView;
    private SparseArray<View> mViews;

    public CommonDialog(Context context, int mLayoutId) {
        super(context);
        this.mContext = context;
        this.mLayoutId = mLayoutId;
        initView();
    }

    private void initView() {
        mViews = new SparseArray<>();
        mConvertView = LayoutInflater.from(mContext).inflate(mLayoutId, null);
        this.setView(mConvertView);
    }

    public <T extends View> T getView(int viewId) {

        View view = mViews.get(viewId);
        if (view == null) {
            view = mConvertView.findViewById(viewId);
            mViews.put(viewId, view);
        }
        return (T) view;
    }


}
